#include <msp430f6638.h>

#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)CPU_F*(double)x/1000000.0)
#define delay_ms(x) __delay_cycles((long)CPU_F*(double)x/1000.0)

#define d 0x01
#define c 0x20
#define b 0x40
#define a 0x80
#define dp 0x10
#define g 0x04
#define f 0x08
#define e 0x02

const char char_gen[] = {

                         a+b+c+d+e+f,   //0
                         b+c,           //1
                         a+b+d+e+g,     //2
                         a+b+c+d+g,     //3
                         b+c+f+g,       //4
                         a+c+d+f+g,      //5
                         a+c+d+e+f+g,   //6
                         a+b+c,         //7
                         a+b+c+d+e+f+g, //8
                         a+b+c+d+f+g,   //9

};

void Init_lcd(void);
void LcdGo(unsigned char Dot);
void LcdBlink(unsigned char doit);
void LCD_Clear(void);
void Init_TS3A5017DR(void);
void Backlight_Enable(void);


void Init_lcd(void){
    LCDBCTL0 = LCDDIV0 + LCDPRE0 + LCDMX1 + LCDSSEL + LCDMX1 + LCD4MUX;
    LCDBPCTL0 = LCDS0 + LCDS1 + LCDS2 + LCDS3 + LCDS4 + LCDS5 + LCDS6 + LCDS7 + LCDS8 + LCDS9 + LCDS10 + LCDS11;
    P5SEL = 0xfc;
}

void LcdGo(unsigned char Dot){
    if(Dot == 1){
        LCDBCTL0 |= LCDON;
    }
    else if(Dot == 1){
        LCDBCTL0 &= ~LCDON;
    }
}


void LcdBlink(unsigned char doit){
    if(doit == 0){
        LCDBCTL0 &= ~LCDSON;
    }
    else if(doit == 1){
        LCDBCTL0 |= LCDSON;
    }





}

void LCD_Clear(void){
    unsigned char index;
    for(index = 0; index < 12; index++){
        LCDMEM[index] = 0;
    }
}



void Init_TS3A5017DR(void){
    P1DIR |= BIT6 + BIT7;
    P1OUT &= ~BIT7;
    P1OUT |= BIT6;

}



void Backlight_Enable(void){
    P8DIR |= BIT0;
    P8OUT |= BIT0;
}

void Backlight_Disable(void){
    P8DIR |= BIT0;
    P8OUT &= ~BIT0;
}

int main(void){
    int i, j;
    WDTCTL = WDTPW + WDTHOLD;
    Init_TS3A5017DR();
    Init_lcd();
    Backlight_Disable();
    LcdGo(1);
    LCD_Clear();
    while(1){
//        for(i=0; i < 6; i++){
//            for(j=0; j < 6; j++){
//                LCDMEM[j] = char_gen[i];
//            }
//            delay_ms(1000);
//        }
        int tag=1;
        for(i=0; i < 6; i++){

            for(j=0; j < 6; j++){
                if(j+tag<7)
                LCDMEM[j] = char_gen[j+tag];
                else
                    LCDMEM[j] = char_gen[j+tag-6];
            }
            delay_ms(1000);
            tag++;
            if(tag==9)  tag=1;
        }
    }
}




















































